import asyncio


async def waiter(event):
    count: int = 0
    while True:
        print(f"waiting...")
        # 等待协程事件
        await event.wait()
        print(f"{count} event.wait() ok")
        count += 1
        # 清除事件: 通过wait()方法设置的事件, 需要手动清除
        event.clear()


async def cmd_control(event):
    while True:
        cmd = input("请输入命令 1: ")
        if cmd == "1":
            event.set()
        else:
            print("未知命令")
        await asyncio.sleep(1)


async def main():
    event = asyncio.Event()
    await asyncio.gather(
        waiter(event),
        cmd_control(event),
    )


if __name__ == "__main__":
    asyncio.run(main())
